<?php
/**
*   @description 栏目
*   @author Xiaohui Zeng
*   @date 2019/12/1
*/
namespace app\blog\controller;
use app\model\CmsMenu;

class menu extends Base {
    /**
 *   @description 获取栏目列表 默认查不隐藏的
 *   @author Xiaohui Zeng
 *   @date 2019/12/1
 */
    public function index() {
        $Redis = new Redis();
        $data = $Redis->get('CmsMenuList');
        if($data) {
            return $data;
        }
        $CmsMenuList = CmsMenu::where(['hide'=>0])->order('sort ASC')->select();
        $arr = [];
        foreach ($CmsMenuList as $item){
            if($item['islast'] == 1) {
                if($item['fid'] == 0) {
                    array_push($arr,$item);
                }
            } else {
                $childList = CmsMenu::where(['hide'=>0,'fid'=>$item["id"]])->order('sort', 'ASC')->select();
                if(!empty($childList)) {
                    $item["childList"] = $childList;
                    array_push($arr,$item);
                }
            }
        }
        $Redis->save('CmsMenuList', $arr,60*60*24); // 栏目缓存24小时
        return $arr;
    }
    /**
     *   @description 获取栏目信息
     *   @author Xiaohui Zeng
     *   @date 2019/12/1
     */
    public function pageInfo($classId) {
        $Redis = new Redis();
        $CmsPageInfoData = $Redis->get('CmsPageInfo-'.$classId);
        if($CmsPageInfoData) {
            $MenuInfo = $CmsPageInfoData;
        } else {
            $MenuInfo = CmsMenu::get($classId);
            $Redis->save('CmsPageInfo-'.$classId, $MenuInfo,60*60*24); // 栏目信息缓存24小时
        }
        return $MenuInfo;
    }
}